<?php

namespace App\Repository\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;

/**
 * Class Company.
 *
 * @package namespace App\Repository\Models;
 */
class Company extends Model implements Transformable
{
    use TransformableTrait;
    use SoftDeletes;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $table = 'company';

    protected $appends = ['step_name'];

    protected $fillable = ['id','user_id','company_name','angent','reg_location','company_address','company_tel','bank','bank_account','licence_type','agnet_licence','tax_certificate','organization_code_certificate','status','apply_at','created_at','updated_at','step','fail_reason','check_at','need_refound','pay_money_num','pay_money_info','is_shop_open','open_at','deleted_at','organization_code','social_unify_number'];

    //申请状态
    public static $step_map = [
        0 => '还未开始',
        1 => '填写了基本信息',
        2 => '已经完成打款信息提交',
        3 => '审核失败打回重新提交',
        4 => '审核成功',
    ];

    public function getStepNameAttribute()    {
        if(isset( $this->attributes['step'])){
            return array_get(self::$step_map, $this->attributes['step']) ? : '';
        }else{
            return '';
        }
    }


    public function companyMaterial(){
        return $this->hasOne(CompanyMaterial::class,'company_id','id');
    }

    public function shop(){
        return $this->hasOne(Shop::class,'sp_cmp_id','id');
    }


}
